package com.dlyk.web;

import com.dlyk.model.UserRole;
import com.dlyk.result.R;
import com.dlyk.service.UserRoleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户角色
 */
@RestController
public class UserRoleController {

    @Resource
    private UserRoleService userRoleService;

    /**
     * 添加用户角色
     */
    @PostMapping("/api/user/role/add")
    public R addUserRole(@RequestBody UserRole userRole) {

        // 这里就不使用Query对象接收了，直接使用UserRole对象接收

        int add = userRoleService.addUserRole(userRole);

        return add >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * 删除用户角色
     */
    @DeleteMapping("/api/user/role/remove")
    public R removeUserRoleByRoleIdAndUserId(Integer roleId, Integer userId) {

        // 这里就不使用Query对象接收了，直接使用UserRole对象接收

        int remove = userRoleService.removeUserRoleByRoleIdAndUserId(roleId, userId);

        return remove >= 1 ? R.OK() : R.FAIL();
    }

}

